package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.ActorMenuDto;
import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.model.ActorMenuEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;


import java.util.List;

/**
 * Created by xu-jiaHui on 2017/4/9.
 */
public interface ActorMenuRepository extends CrudRepository<ActorMenuEntity, Long> {

    /**
     * @Description: 获取角色菜单用于DT
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 14:19
     */

    public List<ActorMenuDto> getActorMenuByActorId(DTRequestDto dtRequestDto, Integer actorId) throws Exception;

    @Query(value = "select count(*) from ActorMenuEntity a inner join MenuEntity  m ON a.menuId = m.menuId where actorId=?1 " +
            "and menuName like concat('%',?2,'%') ")
    public Integer getActorMenuCountByActorId(Integer actorId, String strSearch) throws Exception;

    /**
     * @Description: 根据amId更新角色菜单
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 16:40
     */
    @Modifying
    @Query(value = "update ActorMenuEntity a set a.powerInsert=?2,a.powerDelete=?3,a.powerUpdate=?4,a.powerSelect=?5," +
            "a.powerCheck=?6 where a.amId=?1")
    public Integer updateActorMenuByAmId(Integer amId, Integer powerInsert, Integer powerDelete, Integer powerUpdate,
                                         Integer powerSelect, Integer powerCheck) throws Exception;


    /**
     * @Description: 根据角色Id和菜单Id获取数量
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 17:10
     */
    @Query(value = "select count(*) from ActorMenuEntity a where a.actorId=?1 and a.menuId=?2")
    public Integer getCountByIds(Integer actorId, Integer menuId) throws Exception;

    /**
     * @Description: 通过amId删除信息
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 17:10
     */
    @Modifying
    @Query(value = "delete from ActorMenuEntity a where a.amId=?1")
    public Integer deleteActorMenuByAmId(Integer amId) throws Exception;

    /**
     * @Description: 通过actorId删除信息
     * @Author: xu-jiaHui
     * @Date: 2017/4/9 17:34
     */
    @Modifying
    @Query(value = "delete from ActorMenuEntity a where a.actorId=?1")
    public Integer deleteActorMenuByActorId(Integer actorId) throws Exception;


}
